package org.gikolet.ch2.android.viewer;

import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.view.ContextMenu;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.ContextMenu.ContextMenuInfo;

public abstract class AbstractViewer implements Viewer {

	private ActivityFeature activityFeature;

	private Context context;

	public void onCreate(Bundle savedInstanceState) {
	}

	public void saveInstanceState(Bundle outState) {
	}

	public void restoreInstanceState(Bundle savedInstanceState) {
	}

	public void createView(ViewGroup parent) {
		this.context = parent.getContext();
	}

	public boolean createMenu(Menu menu) {
		return false;
	}

	public void createContextMenu(ContextMenu menu, View view,
			ContextMenuInfo menuInfo) {
	}

	public boolean onMenuItemSelected(MenuItem item) {
		return false;
	}

	public boolean onContextItemSelected(MenuItem item) {
		return false;
	}

	public void setFocus() {
	}

	public ActivityFeature getActivityFeature() {
		return this.activityFeature;
	}

	public void setActivityFeature(ActivityFeature activityFeature) {
		this.activityFeature = activityFeature;
	}

	public Context getContext() {
		return this.context;
	}

	protected void requestView() {
		ActivityFeature activityFeature = this.activityFeature;
		if (activityFeature != null) {
			activityFeature.requestView(this);
		}
	}

	protected void registerForContextMenu(View view) {
		ActivityFeature activityFeature = this.activityFeature;
		if (activityFeature != null) {
			activityFeature.registerForContextMenu(view);
		}
	}

	protected void unregisterForContextMenu(View view) {
		ActivityFeature activityFeature = this.activityFeature;
		if (activityFeature != null) {
			activityFeature.unregisterForContextMenu(view);
		}
	}

	protected Cursor managedQuery(Uri uri, String[] projection,
			String selection, String[] selectionArgs, String sortOrder) {

		ActivityFeature activityFeature = this.activityFeature;
		if (activityFeature == null) {
			throw new IllegalStateException("ViewerManager is null.");
		}
		return activityFeature.managedQuery(uri, projection, selection,
				selectionArgs, sortOrder);
	}

	public boolean dispatchKeyEvent(KeyEvent event) {
		return false;
	}
}
